package com.zenithsun.common.review.dao.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import com.zenithsun.common.bean.ModelType;
import com.zenithsun.common.dao.NativeSQLDaoHibernate;
import com.zenithsun.common.review.dao.ReviewdetailDAO;
import com.zenithsun.common.review.model.Reviewdetail;
import com.zenithsun.news.newsreview.model.NewsReview;

@Repository("reviewdetailDao")
public class ReviewdetailDAOImpl extends NativeSQLDaoHibernate<Reviewdetail> implements ReviewdetailDAO {

	/**
	 * listReviewdetail的执行SQL
	 */
	private String SQL_listReviewdetail="SELECT {RD.*},{P.*} FROM REVIEWDETAIL RD,PERSON P WHERE P.ID=RD.USER_ID AND RD.REV_ID=? ORDER BY RD.CREATE_TIME DESC";
	
	@Override
	protected Class<Reviewdetail> getEntityClass() {
		return Reviewdetail.class;
	}

	@Override
	public List<Reviewdetail> listReviewdetail(String revId) throws Exception {
		SQLQuery query=getSession().createSQLQuery(SQL_listReviewdetail);
		query.addEntity("RD",getEntityClass());
		query.addJoin("P","RD.person");
		//设置查询条件
		query.setParameter(0, revId);
		//设置分页条件
		List list=queryBySQL(query);
		List<Reviewdetail> reviewdetailList=new ArrayList<Reviewdetail>();
		for(Iterator iterator = list.iterator();iterator.hasNext();){  
	        //每个集合元素都是Person、MyEvent所组成的数组  
	        Object[] objects = (Object[]) iterator.next();  
	        reviewdetailList.add((Reviewdetail) objects[0]);
	    }  
		return reviewdetailList;
	}
}
